#!/bin/sh
export UNICONF=unix:/filesystem/VERSA/uniconfd
export PATH=/usr/sbin:/usr/bin:/sbin:/bin

# used by /etc/init.d/rc
export debug="/etc/init.d/rc.log"

status()                                                                      
{                                                                             
	CODE=$1
	shift
	MESSAGE="$@"
	echo "[$CODE] $MESSAGE"
	uni set /tmp/addons/$MYNAME/status "$CODE"
	uni set /tmp/addons/$MYNAME/status\ message "$MESSAGE"
}

stopme()
{
	trap "" TERM QUIT INT
	
	status 1 "Stopping rc 6..."
	PREVLEVEL=2 chroot filesystem /etc/init.d/rc 6
	status 1 "Stopped."
	
	exit
}


trap stopme TERM QUIT INT


status 1 "Starting rcS..."
chroot filesystem /etc/init.d/rcS || stopme

status 1 "Starting rc 2..."
chroot filesystem /etc/init.d/rc 2 || stopme

status 2 "Running."

while :; do
	# this looks funny, but it's needed because "wait" will interrupt
	# and run the 'trap' if we get a signal, but sleep won't.
	sleep 600 &
	wait
done

exit 0
